package trials;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

public class Three {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		 try {
			 Directory fdr = FSDirectory.open(new File("C:\\JKR\\Gunscape\\MethIndex\\"));
				IndexSearcher searcher = new IndexSearcher(fdr,true);	 
				
				Query query = new QueryParser(Version.LUCENE_35,"Method_println",new org.apache.lucene.analysis.KeywordAnalyzer()).parse("scb*modifi*".toLowerCase());
				
				
				TopScoreDocCollector collector = TopScoreDocCollector.create(10000, true);
			
			searcher.search(query, collector);
			 ScoreDoc[] hits = collector.topDocs().scoreDocs;
			// System.out.println(hits.length+" <> "+collector.topDocs().totalHits);
			 for(ScoreDoc sd :hits)
			 {	//System.out.println(searcher.doc(sd.doc).get(searcher.doc(sd.doc).get("Class_Name")+".Method_full")+"\t"+searcher.doc(sd.doc).get("Class_Name"));
			 //String fieldname=searcher.doc(sd.doc).get("Class_Name").toString()+".Method_full";
			 //System.out.println("Class "+searcher.doc(sd.doc).get("Class_Name").toString()+" has "+searcher.doc(sd.doc).getFieldables(fieldname).length+"Methods");
				// for(Fieldable fd :searcher.doc(sd.doc).getFieldables(fieldname))
				// 	System.out.println("\t"+fd.name() +" ^^ "+fd.stringValue());
			 
				 System.out.println(searcher.doc(sd.doc).get("Method_println"));
			 } 
			 searcher.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		 //assertEquals("JDwA", 1, hits.length());
		//t = new Term("subject", "junit");
		//hits = searcher.search(new TermQuery(t));
		
		

	}

}
